import GameObject from "./GameObject";
import Utils from "./utils";
import GameConst from "./GameConst";

export default class CookieTweenSprite extends GameObject{
    constructor(t, n, r) {
        super();
        var i = this;
        var s = Utils.createSpriteFromSpritesheet(r == 5 ? "bush root" : r == 10 ? "chocolate black x3" : r == 0 ? "cookie" : r == 1 ? "cookie honey" : "cookie x3");
        if (r == 10 || r == 5) {
            Utils.setReg(s, .5, .5);
            s.x = t;
            s.y = n;
        } else {
            s.pivotX = s.pivotY = 4 + GameConst.TILE_SIZE / 2;
            s.x = t + GameConst.TILE_SIZE / 2;
            s.y = n + GameConst.TILE_SIZE / 2;
        }
        this.sprite = s;
        var o = r == 10 ? GameConst.level.blockDestroyLayer : GameConst.level.underGemLayer;
        o.addChild(s);
        Laya.Tween.to(s,{
            alpha: 0,
            scaleX: r == 0 || r == 10 || r == 5 ? 1.3 : 1,
            scaleY: r == 0 || r == 10 || r == 5 ? 1.3 : 1
        }, 135, Laya.Ease.quadOut,Laya.Handler.create(this,this.onComplete));
    }
    onComplete () {
        this.destroy();
    };
}
